import { defineStore } from "pinia"

export const playlistStore = defineStore('playlist', {
    state: () => {
        return {
            playlist: [
                // {
                //     name: 'name1',
                //     artist: 'artist1',
                //     url: 'url1.mp3',
                //     cover: 'cover1.jpg'
                // }
            ]
        }
    },
    getters: {
        // this 的作用域是 store
        // add: (state) => {
        //     state.playlist.push({
        //         name: 'name2',
        //         artist: 'artist2',
        //         url: 'url2.mp3',
        //         cover: 'cover2.jpg'
        //     })
        // },
        // pop: (state) => {
        //     state.playlist.pop()
        // }
        currentSongName: (state) => {
            if (state.playlist.length > 0) {
                return state.playlist[state.playlist.length - 1].name
            }
            return '没有歌曲在播放'
        }
    },
    actions: {
        addSongToPlaylist(song) {
            this.playlist.push(song)
            return '添加歌曲成功'
        },
        clearPlayList() {
            this.playlist = []
            return '清空播放列表成功'
        }
    }
})